package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.urea.system.domain.vo.FleetUserVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.FleetUser;
import com.urea.system.service.IFleetUserService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 车队用户关系Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/fleet/user")
public class FleetUserController extends BaseController
{
    @Autowired
    private IFleetUserService fleetUserService;

    /**
     * 查询车队用户关系列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(FleetUserVo fleetUser)
    {
        startPage();
        List<FleetUserVo> list = fleetUserService.selectFleetUserList(fleetUser);
        return getDataTable(list);
    }

    /**
     * 导出车队用户关系列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:export')")
    @Log(title = "车队用户关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FleetUserVo fleetUser)
    {
        List<FleetUserVo> list = fleetUserService.selectFleetUserList(fleetUser);
        ExcelUtil<FleetUserVo> util = new ExcelUtil<FleetUserVo>(FleetUserVo.class);
        util.exportExcel(response, list, "车队用户关系数据");
    }

    /**
     * 获取车队用户关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fleetUserService.selectFleetUserById(id));
    }

    /**
     * 新增车队用户关系
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:add')")
    @Log(title = "车队用户关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FleetUser fleetUser)
    {
        return toAjax(fleetUserService.insertFleetUser(fleetUser));
    }

    /**
     * 修改车队用户关系
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:edit')")
    @Log(title = "车队用户关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FleetUser fleetUser)
    {
        return toAjax(fleetUserService.updateFleetUser(fleetUser));
    }

    /**
     * 删除车队用户关系
     */
    @PreAuthorize("@ss.hasPermi('fleet:user:remove')")
    @Log(title = "车队用户关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fleetUserService.deleteFleetUserByIds(ids));
    }
}
